package com.taskflow.controller;

import com.taskflow.common.Result;
import com.taskflow.entity.EntryData;
import com.taskflow.service.ExternalApiService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 外部API测试控制器
 */
@Slf4j
@RestController
@RequestMapping("/api-test")
@CrossOrigin
public class ExternalApiTestController {

    @Autowired
    private ExternalApiService externalApiService;

    /**
     * 测试外部API调用
     */
    @GetMapping("/query")
    public Result<List<EntryData>> testQuery(
            @RequestParam String companyTaxNo,
            @RequestParam(defaultValue = "1") Integer declareDateRange) {
        try {
            log.info("测试外部API调用: companyTaxNo={}, declareDateRange={}", companyTaxNo, declareDateRange);
            
            List<EntryData> result = externalApiService.queryEntryData(companyTaxNo, declareDateRange);
            
            log.info("查询成功，返回 {} 条数据", result.size());
            return Result.success(result);
            
        } catch (Exception e) {
            log.error("测试外部API调用失败", e);
            return Result.error("测试失败: " + e.getMessage());
        }
    }
}

